//
// Created by Administrator on 2018/10/20.
//
#ifdef __cplusplus
extern "C" {
#endif

#include <stdlib.h>
#include <stdio.h>
#include "modbus_plugin.h"

modbus_mapping_t *
replace_modbus_mapping_cache(modbus_mapping_t *sp, uint8_t *bit_address, int bit_n, uint8_t *input_bit_address,
                             int input_bit_n, uint16_t *input_registers_address, int input_registers_n,
                             uint16_t *registers_address, int registers_n) {
    if( sp == NULL){
        return NULL;
    }
    if(bit_address != NULL){
        free(sp->tab_bits);
        sp->tab_bits = bit_address;
        sp->nb_bits = bit_n;
        printf("modbus mapping tab_bits is %p\n", (void*)bit_address);
    }
    if(input_bit_address != NULL){
        free(sp->tab_input_bits);
        sp->tab_input_bits = input_bit_address;
        sp->nb_input_bits = input_bit_n;
    }
    if(input_registers_address != NULL){
        free(sp->tab_input_registers);
        sp->tab_input_registers = input_registers_address;
        sp->nb_input_registers = input_registers_n;
    }
    if(registers_address != NULL){
        free(sp->tab_registers);
        sp->tab_registers = registers_address;
        sp->nb_registers = registers_n;
        printf("modbus mapping tab_registers is %p\n", (void*)registers_address);
    }
    return sp;
}

#ifdef __cplusplus
}
#endif